﻿using System;
using System.ComponentModel;
using System.Linq;
using Chapter11.Model;

namespace Chapter11.Queries
{
    //用分配者来分组缺陷
    [Description("Listing 11.17")]
    class GroupDefectsByAssignee
    {
        static void Main()
        {
            var query = from defect in SampleData.AllDefects
                        where defect.AssignedTo != null //过滤未分配的缺陷
                        group defect by defect.AssignedTo;//用分配者来分组

            foreach (var entry in query)
            {
                Console.WriteLine(entry.Key.Name);//使用每个条目的键：分配者，User类型
                foreach (var defect in entry)//遍历数据条目的子序列
                {
                    Console.WriteLine("  ({0}) {1}",
                                      defect.Severity,
                                      defect.Summary);
                }
                Console.WriteLine();
            }
        }
    }
}
